package be.quadreg.dojo.model;

import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;

import be.quadreg.dojo.model.entity.AddressMemberAttribute;
import be.quadreg.dojo.model.entity.BeltHistoryMemberAttribute;
import be.quadreg.dojo.model.entity.BeltHistoryMemberAttribute.Belt;
import be.quadreg.dojo.model.entity.EmailMemberAttribute;
import be.quadreg.dojo.model.entity.Member;
import be.quadreg.dojo.model.entity.MemberSubscription;
import be.quadreg.dojo.model.entity.MemberSubscription.SubscriptionType;
import be.quadreg.dojo.model.entity.SubscriptionHistoryMemberAttribute;
import be.quadreg.dojo.persistence.GenericDAO;

public class MemberManager {
	private GenericDAO memberPersistence;

	public MemberManager() {
		memberPersistence = GenericDAO.getInstance();
	}

	public void createMember() {
		// todo: implement
		Member m = new Member();
		AddressMemberAttribute ma = new AddressMemberAttribute();
		ma.setStreet("MyStreet");

		MemberSubscription subs = new MemberSubscription(new GregorianCalendar(
				2009 + 1900, GregorianCalendar.JULY, 2).getTime(),
				new GregorianCalendar(2010 + 1900, GregorianCalendar.JULY, 2)
						.getTime(), SubscriptionType.YEAR, 140.5, "Euro");
		MemberSubscription subs2 = new MemberSubscription(Calendar
				.getInstance().getTime(), new GregorianCalendar(2011 + 1900,
				GregorianCalendar.JULY, 2).getTime(), SubscriptionType.YEAR,
				140.5, "Euro");
		SubscriptionHistoryMemberAttribute subMa = new SubscriptionHistoryMemberAttribute();
		subMa.addSubscription(subs);
		subMa.addSubscription(subs2);

//		subMa.setCurrentSubscription(subs2);
//
		BeltHistoryMemberAttribute bhMa = new BeltHistoryMemberAttribute();
		bhMa.setBelt(new GregorianCalendar(2011 + 1900,
				GregorianCalendar.JULY, 2).getTime(), Belt.BROWN);
		bhMa.setBelt(new GregorianCalendar(2010 + 1900,
				GregorianCalendar.JULY, 2).getTime(), Belt.BLUE);
		bhMa.setBelt(new GregorianCalendar(2009 + 1900,
				GregorianCalendar.JULY, 2).getTime(), Belt.YELLOW);

				
		m.addAttribute(ma);
		m.addAttribute(new EmailMemberAttribute("test@email.com"));
		m.addAttribute(subMa);
		m.addAttribute(bhMa);
		memberPersistence.persistMember(m);
	}

	public Collection<Member> getAllMembers() {
		return memberPersistence.getAllMembers();
	}
}
